package 线程通信;

import java.util.ArrayList;
import java.util.List;

public class Desk {

    private List<String> list = new ArrayList<>();

    public synchronized void put() throws InterruptedException {
        String name = Thread.currentThread().getName();
        if (list.size() == 0) {
            list.add(name + "做的包子");
            System.out.println(name + "做了一个包子");
        }
        this.notifyAll();
        this.wait();
    }

    public synchronized void get() throws InterruptedException {
        String name = Thread.currentThread().getName();
        if (list.size() == 1) {
            String s = list.get(0);
            System.out.println(name + "吃了" + s);
            list.clear();
        }
        this.notifyAll();
        this.wait();
    }
}
